<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="goodsCreateForm" :model="goodsCreateFormData" :rules="rules" size="mini"
        label-width="100px">
        <el-col :span="12">
          <el-form-item label="商品名称" prop="goodsName">
            <el-input v-model="goodsCreateFormData.goodsName" placeholder="请输入商品名称" :maxlength="20"
              show-word-limit clearable prefix-icon='el-icon-goods' :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商品单价" prop="goodsValue">
            <el-input v-model="goodsCreateFormData.goodsValue" placeholder="请输入商品单价" clearable
              prefix-icon='el-icon-star-on' :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="商品数量" prop="goodsNumber">
            <el-input v-model="goodsCreateFormData.goodsNumber" placeholder="请输入商品数量" clearable
              prefix-icon='el-icon-s-release' :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="在售状态" prop="onSale">
            <el-select v-model="goodsCreateFormData.onSale" placeholder="请选择在售状态" :style="{width: '100%'}">
              <el-option v-for="(item, index) in onSaleOptions" :key="index" :label="item.label"
                :value="item.value" :disabled="item.disabled"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">创建商品</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </div>
</template>
<script>
import {goodsCreate} from '@/api/storage'
export default {
  components: {},
  props: [],
  data() {
    return {
      goodsCreateFormData: {
        goodsName: undefined,
        goodsValue: undefined,
        goodsNumber: undefined,
        onSale: 1,
      },
      rules: {
        goodsName: [{
          required: true,
          message: '请输入商品名称',
          trigger: 'blur'
        }],
        goodsValue: [{
          required: true,
          message: '请输入商品单价',
          trigger: 'blur'
        }],
        goodsNumber: [{
          required: true,
          message: '请输入商品数量',
          trigger: 'blur'
        }],
        onSale: [{
          required: true,
          message: '请选择在售状态',
          trigger: 'change'
        }],
      },
      onSaleOptions: [{
        "label": "在售",
        "value": 1
      }, {
        "label": "下架",
        "value": 0
      }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['goodsCreateForm'].validate(valid => {
        if (!valid) return
        goodsCreate(this.goodsCreateFormData).then(res => {
          this.resetForm()
        })
      })
    },
    resetForm() {
      this.$refs['goodsCreateForm'].resetFields()
    },
  }
}

</script>
<style>
</style>